<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>网站首页</title>
    <link rel="stylesheet" href="css/tt.css">
    <link rel="stylesheet" href="css/simplePagination.css">
</head>
<body>
<div class="top">
    <span class="top-left">下载APP</span>
    <span class="top-left"> 北京         晴天</span>
    <span class="top-right">更多产品</span>
</div>

<div class="container">

    <div class="left">
        <a>
            <img src="img/logo.png"><br/>
        </a>

        <ul>
            <li>
                <a class="channel-item active" href="#">
                    <span>
                        推荐
                    </span>
                </a>
            </li>

            <li><a class="channel-item" href="#">
                <span>
                    视频
                </span>
            </a></li>

            <li><a class="channel-item" href="#">
                <span>
                    热点
                </span>
            </a></li>

            <li><a class="channel-item" href="#">
                <span>
                    直播
                </span>
            </a></li>

            <li><a class="channel-item" href="#">
                <span>
                    图片
                </span>
            </a></li>

            <li><a class="channel-item" href="#">
                <span>
                    娱乐
                </span>
            </a></li>

            <li><a class="channel-item" href="#">
                <span>
                    游戏
                </span>
            </a></li>

            <li><a class="channel-item" href="#">
                <span>
                    体育
                </span>
            </a></li>

        </ul>

    </div>
    <div class="center">
        <ul class="news_list">


        </ul>

        <!-- <div class="loading" style="text-align: center; height: 80px">
             <img src="img/loading2.gif" height="100%">
         </div>-->

        <div class="content">
            <div class="pagination-holder clearfix">
                <div id="light-pagination" class="pagination"></div>
            </div>
        </div>

        <div id="no" style="text-align: center;color: red;font-size: 20px"></div>
    </div>
</div>
</body>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/jquery.simplePagination.js"></script>
<script>
    function findPage(pageNum) {
        //进入页面就要加载第一页数据
        $.get("/newsServlet",{pageNum:pageNum},function(data){
            let newsArray = data.list;
            $(".news_list").html("");
            $.each(newsArray,function () {

                $(".news_list").append("<li>\n" +
                    "                <div class=\"title-box\">\n" +
                    "                    <a href=\"#\" class=\"link\">\n" +
                    "                        "+this.title+"\n"+
                    "                        <hr>\n" +
                    "                    </a>\n" +
                    "                </div>\n" +
                    "            </li>");
            })
            //处理分页条的展示
            //4.为分页按钮区域设置页数参数(总页数和当前页)
            $("#light-pagination").pagination({
                pages:data.pages,//总页数
                currentPage:data.pageNum//当前页

            });

            //给分页条中的那些按钮绑定单击事件

            $(".page-link").click(function () {
                // alert(this.innerHTML);
                let text = this.innerHTML;
                if (text=="Next"){
                    findPage(data.pageNum+1);
                }else if(text=="Prev"){
                    findPage(data.pageNum-1);
                }else {
                    findPage(text);
                }
            });

        },"json");
    }
    findPage(1);
</script>
</html>